package com.wmx.designMode.observer;

import java.util.ArrayList;

/**********************************
 * @author wmx
 * @date 2019/8/16 13:49
 * @description:
 * @version 1.0
 ************************************/
public class Subject {
    ArrayList<AbsObserver> observers = new ArrayList<>();
    private String str ;

    public String getStr() {
        return str;
    }

    public void setStr(String str) {
        this.str = str;
        notifyObserver();
    }

    //注册观察者
    public void register(AbsObserver observer){
        observers.add(observer);
    }


    //通知所有的观察者
    private void notifyObserver(){
        if(observers.isEmpty()){
            System.out.println("请注册观察者");
        }

        for (AbsObserver a: observers) {
            a.update();
        }
    }

}
